package com.example.crm.servlet;
import com.example.crm.dao.ConnectDAO;
import com.example.crm.dao.CustomerDAO;
import com.example.crm.domain.Connect;
import com.example.crm.domain.Customer;
import com.example.crm.domain.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/addconnect")
public class InsertConnectServlet extends HttpServlet
{
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {


		req.setCharacterEncoding("utf-8");

		HttpSession s = req.getSession();
		User user = (User) s.getAttribute("user");


		String name=req.getParameter("connect_name");
		String tel=req.getParameter("connect_tel");
		System.out.println("----------------");
		Connect c = new Connect(-1,name,tel);

		System.out.println("----------------");
		System.out.println(name+tel);

		// 2. 调用DAO
		ConnectDAO dao = new ConnectDAO();
		try {
			int result = dao.insert(c);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		// 3. 跳转列表页
		//resp.sendRedirect("jsp/customer/list.jsp");
		resp.sendRedirect("listconnect");

	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doGet(req, resp);
	}
}
